<?php
/**
 * This file handles the logic of deciding which
 * loop to use. Results are filterable, so that
 * child themes can register custom loops and use
 * them rather than the default list.
 *
 * ===================================================
 * NOTE: Defining your own loop is almost always
 * unnecessary, as the default loop is full of
 * action hooks to which can use to add/remove custom
 * code.
 *
 * See /lib/loops/loops.php for more details.
 * ===================================================
 *
 * @author Nathan Rice
 * @package Prodigy
 */

/**
 * This function is used to determine what loop we should use
 * it is hooked to the prodigy_loop action hook
 *
 * @since 0.1
 */
add_action('prodigy_loop','loop_logic');
function loop_logic() {
	//	defaults, filterable. most are set to use
	//	the default loop, 404 being the exception.
	$defaults = array(
		'front_page' => 'prodigy_loop_default',
		'home' => 'prodigy_loop_default',
		'single' => 'prodigy_loop_default',
		'page' => 'prodigy_loop_default',
		'archive' => 'prodigy_loop_default',
		'search' => 'prodigy_loop_default',
		'404' => 'prodigy_loop_404'
	);
	
	//	lets the child theme redefine the default loops used
	//	for various content types.
	$defaults = apply_filters('loop_logic_defaults',$defaults);
	
	//	these statements determine what we are viewing, and
	//	define the loop to use based on that information.
	if (is_front_page())	$loop = $defaults['front_page'];
	
	elseif	(is_home())		$loop = $defaults['home'];
	elseif	(is_single())	$loop = $defaults['single'];
	elseif	(is_page()) 	$loop = $defaults['page'];
	elseif	(is_archive())	$loop = $defaults['archive'];
	elseif	(is_search())	$loop = $defaults['search'];
	elseif	(is_404())		$loop = $defaults['404'];
	
	//	Let the child them define its own loop, if necessary.
	//	I highly recommend making it conditional, though, like above.
	$loop = apply_filters('loop_logic',$loop);
	
	$loop(); //	Execute the loop
}
?>